package com.yxinsur.imc.business.service.impl;

import com.aliyun.openservices.ons.api.Message;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.List;

import com.yxinsur.imc.business.domain.ImcRocketmqMessage;
import com.yxinsur.imc.business.mapper.ImcRocketmqMessageMapper;
import com.yxinsur.imc.business.service.IImcRocketmqMessageService;
import com.yxinsur.imc.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 消息队列信息Service业务层处理
 *
 * @author imc
 * @date 2021-12-10
 */
@Service
public class ImcRocketmqMessageServiceImpl extends ServiceImpl<ImcRocketmqMessageMapper, ImcRocketmqMessage> implements IImcRocketmqMessageService {
    @Autowired
    private ImcRocketmqMessageMapper imcRocketmqMessageMapper;

    /**
     * 查询消息队列信息
     *
     * @param id 消息队列信息ID
     * @return 消息队列信息
     */
    @Override
    public ImcRocketmqMessage selectImcRocketmqMessageById(String id) {
        return imcRocketmqMessageMapper.selectImcRocketmqMessageById(id);
    }

    /**
     * 查询消息队列信息列表
     *
     * @param imcRocketmqMessage 消息队列信息
     * @return 消息队列信息
     */
    @Override
    public List<ImcRocketmqMessage> selectImcRocketmqMessageList(ImcRocketmqMessage imcRocketmqMessage) {
        return imcRocketmqMessageMapper.selectImcRocketmqMessageList(imcRocketmqMessage);
    }

    /**
     * 新增消息队列信息
     *
     * @param imcRocketmqMessage 消息队列信息
     * @return 结果
     */
    @Override
    public int insertImcRocketmqMessage(ImcRocketmqMessage imcRocketmqMessage) {
        imcRocketmqMessage.setCreateTime(DateUtils.getNowDate());
        return imcRocketmqMessageMapper.insertImcRocketmqMessage(imcRocketmqMessage);
    }

    /**
     * 修改消息队列信息
     *
     * @param imcRocketmqMessage 消息队列信息
     * @return 结果
     */
    @Override
    public int updateImcRocketmqMessage(ImcRocketmqMessage imcRocketmqMessage) {
        imcRocketmqMessage.setUpdateTime(DateUtils.getNowDate());
        return imcRocketmqMessageMapper.updateImcRocketmqMessage(imcRocketmqMessage);
    }

    /**
     * 批量删除消息队列信息
     *
     * @param ids 需要删除的消息队列信息ID
     * @return 结果
     */
    @Override
    public int deleteImcRocketmqMessageByIds(String[] ids) {
        return imcRocketmqMessageMapper.deleteImcRocketmqMessageByIds(ids);
    }

    /**
     * 删除消息队列信息信息
     *
     * @param id 消息队列信息ID
     * @return 结果
     */
    @Override
    public int deleteImcRocketmqMessageById(String id) {
        return imcRocketmqMessageMapper.deleteImcRocketmqMessageById(id);
    }

    @Override
    public void saveMessage(Message message) {
        ImcRocketmqMessage imcRocketmqMessage = new ImcRocketmqMessage();
        imcRocketmqMessage.setTopic(message.getTopic());
        imcRocketmqMessage.setTag(message.getTag());
        imcRocketmqMessage.setMessageId(message.getMsgID());
        imcRocketmqMessage.setMessageKey(message.getKey());
        imcRocketmqMessage.setMessageBody(new String(message.getBody()));
        imcRocketmqMessageMapper.insertImcRocketmqMessage(imcRocketmqMessage);
    }
}
